import Vue from 'vue'
import './use'
import './global-com'
import './global-prototype'
import {getIsTokenAndInfo} from '@/common/type'
import { goLogin } from '@/common/base'
Vue.mixin({
  methods:{
    //获取信息信息
    getUserInfoValue(cb){
      const token = uni.getStorageSync('token')
      const { userPid, userPname } = this.$store.state.userInfo
      if (!token) {
        goLogin()
      } else {
        getIsTokenAndInfo()
          .then((res) => {
            const { result } = res
            if (result) {
              if (!userPid.length || !userPname.length) {
                this.$api.personalModal()
                return false
              }
              return cb&&cb(result)
            } else {
              goLogin()
            }
          })
          .catch((e) => {
            goLogin()
          })
      }
    },
    //判断是否有token在
    onTokenCbStorageSync(cb,dec=1000){
      let token = uni.getStorageSync('token')
      if (token) {
        setTimeout(() => {
          return cb&&cb(token)
        }, dec)
      } else {
        goLogin()
      }
    }
  }
})
